package com.company;

import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        Map<String,String> hashMaps = new HashMap<>();
        hashMaps.put("M_Open","(int Nbr)");
        hashMaps.put("M_Open_VidPid","(int Vid, int Pid)");
        hashMaps.put("M_ScanAndOpen","()");
        hashMaps.put("M_Close","(int m_hdl)");
        hashMaps.put("M_Delay","(int time)");
        hashMaps.put("M_DelayRandom","(int Min_time, int Max_time)");
        hashMaps.put("M_RandDomNbr","(int Min_V, int Max_V)");
        hashMaps.put("M_GetDevSn","(int m_hdl, int dwp_LenResponse, Pointer ucp_Response)");
        hashMaps.put("M_GetAbsCfg","(int m_hdl)");
        hashMaps.put("M_SetAbsCfg","(int m_hdl, int e1d0)");
        hashMaps.put("M_ChkSupportMdy","(int m_hdl)");
        hashMaps.put("M_SetNewVidPid","(int m_hdl, int mVid, int mPid, int sVid, int sPid)");
        hashMaps.put("M_ResetVidPid","(int m_hdl)");
        hashMaps.put("M_GetVidPid","(int m_hdl, int IdIndex)");
        hashMaps.put("M_ReEnum","(int m_hdl)");
        hashMaps.put("M_ChkSupportProdStrMdy","(int m_hdl)");
        hashMaps.put("M_SetProdStr","(int m_hdl, int m0s1, int LenOfStr,Pointer ucp_Str)");
        hashMaps.put("M_InitParam","(int m_hdl)");
        hashMaps.put("M_SetParam","(int m_hdl, int ParamType, int Param1,int Param2)");
        hashMaps.put("M_SetW24GParam","(int m_hdl, int Power, int Chn, int Addr)");
        hashMaps.put("M_GetW24GParam","(int m_hdl, Pointer Power, Pointer Chn, Pointer Addr)");
        hashMaps.put("M_SetUserData","(int m_hdl, int dw_LenUserData, Pointer ucp_UserData)");
        hashMaps.put("M_VerifyUserData","(int m_hdl, int dw_LenUserData, Pointer ucp_UserData)");
        hashMaps.put("M_ChkSupportEnc","(int m_hdl)");
        hashMaps.put("M_ChkPwStat","(int m_hdl)");
        hashMaps.put("M_SetPw","(int m_hdl, int PwLen, int PwMaxCnt, Pointer ucp_pw)");
        hashMaps.put("M_VerifyPw","(int m_hdl, int PwLen, Pointer ucp_pw)");
        hashMaps.put("M_WrEncData","(int m_hdl, int DataLen, Pointer ucp_data)");
        hashMaps.put("M_RdEncData","(int m_hdl, int DataLen, Pointer ucp_data)");
        hashMaps.put("M_KeyPress","(int m_hdl, int HidKeyCode, int Nbr)");
        hashMaps.put("M_KeyDown","(int m_hdl, int HidKeyCode)");
        hashMaps.put("M_KeyUp","(int m_hdl, int HidKeyCode)");
        hashMaps.put("M_KeyState","(int m_hdl, int HidKeyCode)");
        hashMaps.put("M_KeyPress2","(int m_hdl, int KeyCode, int Nbr)");
        hashMaps.put("M_KeyDown2","(int m_hdl, int KeyCode)");
        hashMaps.put("M_KeyUp2","(int m_hdl, int KeyCode)");
        hashMaps.put("M_KeyState2","(int m_hdl, int KeyCode)");
        hashMaps.put("M_ReleaseAllKey","(int m_hdl)");
        hashMaps.put("M_NumLockLedState","(int m_hdl)");
        hashMaps.put("M_CapsLockLedState","(int m_hdl)");
        hashMaps.put("M_ScrollLockLedState","(int m_hdl)");
        hashMaps.put("M_KeyInputString","(int m_hdl, Pointer InputStr, int InputLen)");
        hashMaps.put("M_KeyInputStringGBK","(int m_hdl, Pointer InputStr, int InputLen)");
        hashMaps.put("M_KeyInputStringUnicode","(int m_hdl, Pointer InputStr, int InputLen)");
        hashMaps.put("M_LeftClick","(int m_hdl, int Nbr)");
        hashMaps.put("M_LeftDoubleClick","(int m_hdl, int Nbr)");
        hashMaps.put("M_LeftDown","(int m_hdl)");
        hashMaps.put("M_LeftUp","(int m_hdl)");
        hashMaps.put("M_RightClick","(int m_hdl, int Nbr)");
        hashMaps.put("M_RightDown","(int m_hdl)");
        hashMaps.put("M_RightUp","(int m_hdl)");
        hashMaps.put("M_MiddleClick","(int m_hdl, int Nbr)");
        hashMaps.put("M_MiddleDown","(int mhdl)");
        hashMaps.put("M_MiddleUp","(int m_hdl)");
        hashMaps.put("M_ReleaseAllMouse","(int m_hdl)");
        hashMaps.put("M_MouseKeyState","(int m_hdl, int MouseKeyCode)");
        hashMaps.put("M_MouseWheel","(int m_hdl,int Nbr)");
        hashMaps.put("M_ResetMousePos","(int m_hdl)");
        hashMaps.put("M_MoveR","(int m_hdl,int x, int y)");
        hashMaps.put("M_ MoveR_D","(int m_hdl,int x, int y)");
        hashMaps.put("M_MoveTo","(int m_hdl,int x, int y)");
        hashMaps.put("M_ MoveTo_D","(int m_hdl,int x, int y)");
        hashMaps.put("M_GetCurrMousePos","(int m_hdl,Pointer x, Pointer y)");
        hashMaps.put("M_GetCurrMousePosX","(int m_hdl)");
        hashMaps.put("M_GetCurrMousePosY","(int m_hdl)");
        hashMaps.put("M_MoveR2","(int m_hdl,int x, int y)");
        hashMaps.put("M_ MoveR2_D","(int m_hdl,int x, int y)");
        hashMaps.put("M_MoveTo2","(int m_hdl,int x, int y)");
        hashMaps.put("M_ MoveTo2_D","(int m_hdl,int x, int y)");
        hashMaps.put("M_GetCurrMousePos2","(Pointer x, Pointer y)");
        hashMaps.put("M_ResolutionUsed","(int m_hdl,int x, int y)");
        hashMaps.put("M_MoveTo3","(int m_hdl,int x, int y)");
        hashMaps.put("M_MoveTo3_D","(int m_hdl,int x, int y)");
        //=====================================================================================================
        Map<String,String> api = new HashMap<>();
        api.put("M_Open","(Nbr)");
        api.put("M_Open_VidPid","(Vid, Pid)");
        api.put("M_ScanAndOpen","()");
        api.put("M_Close","(m_hdl)");
        api.put("M_Delay","(time)");
        api.put("M_DelayRandom","(Min_time, Max_time)");
        api.put("M_RandDomNbr","(Min_V, Max_V)");
        api.put("M_GetDevSn","(m_hdl, dwp_LenResponse, ucp_Response)");
        api.put("M_GetAbsCfg","(m_hdl)");
        api.put("M_SetAbsCfg","(m_hdl, e1d0)");
        api.put("M_ChkSupportMdy","(m_hdl)");
        api.put("M_SetNewVidPid","(m_hdl, mVid, mPid, sVid, sPid)");
        api.put("M_ResetVidPid","(m_hdl)");
        api.put("M_GetVidPid","(m_hdl, IdIndex)");
        api.put("M_ReEnum","(m_hdl)");
        api.put("M_ChkSupportProdStrMdy","(m_hdl)");
        api.put("M_SetProdStr","(m_hdl, m0s1, LenOfStr,ucp_Str)");
        api.put("M_InitParam","(m_hdl)");
        api.put("M_SetParam","(m_hdl, ParamType, Param1,Param2)");
        api.put("M_SetW24GParam","(m_hdl, Power, Chn, Addr)");
        api.put("M_GetW24GParam","(m_hdl, Power, Chn, Addr)");
        api.put("M_SetUserData","(m_hdl, dw_LenUserData, ucp_UserData)");
        api.put("M_VerifyUserData","(m_hdl, dw_LenUserData, ucp_UserData)");
        api.put("M_ChkSupportEnc","(m_hdl)");
        api.put("M_ChkPwStat","(m_hdl)");
        api.put("M_SetPw","(m_hdl, PwLen, PwMaxCnt, ucp_pw)");
        api.put("M_VerifyPw","(m_hdl, PwLen, ucp_pw)");
        api.put("M_WrEncData","(m_hdl, DataLen, ucp_data)");
        api.put("M_RdEncData","(m_hdl, DataLen, ucp_data)");
        api.put("M_KeyPress","(m_hdl, HidKeyCode, Nbr)");
        api.put("M_KeyDown","(m_hdl, HidKeyCode)");
        api.put("M_KeyUp","(m_hdl, HidKeyCode)");
        api.put("M_KeyState","(m_hdl, HidKeyCode)");
        api.put("M_KeyPress2","(m_hdl, KeyCode, Nbr)");
        api.put("M_KeyDown2","(m_hdl, KeyCode)");
        api.put("M_KeyUp2","(m_hdl, KeyCode)");
        api.put("M_KeyState2","(m_hdl, KeyCode)");
        api.put("M_ReleaseAllKey","(m_hdl)");
        api.put("M_NumLockLedState","(m_hdl)");
        api.put("M_CapsLockLedState","(m_hdl)");
        api.put("M_ScrollLockLedState","(m_hdl)");
        api.put("M_KeyInputString","(m_hdl, InputStr, InputLen)");
        api.put("M_KeyInputStringGBK","(m_hdl, InputStr, InputLen)");
        api.put("M_KeyInputStringUnicode","(m_hdl, InputStr, InputLen)");
        api.put("M_LeftClick","(m_hdl, Nbr)");
        api.put("M_LeftDoubleClick","(m_hdl, Nbr)");
        api.put("M_LeftDown","(m_hdl)");
        api.put("M_LeftUp","(m_hdl)");
        api.put("M_RightClick","(m_hdl, Nbr)");
        api.put("M_RightDown","(m_hdl)");
        api.put("M_RightUp","(m_hdl)");
        api.put("M_MiddleClick","(m_hdl, Nbr)");
        api.put("M_MiddleDown","(mhdl)");
        api.put("M_MiddleUp","(m_hdl)");
        api.put("M_ReleaseAllMouse","(m_hdl)");
        api.put("M_MouseKeyState","(m_hdl, MouseKeyCode)");
        api.put("M_MouseWheel","(m_hdl,Nbr)");
        api.put("M_ResetMousePos","(m_hdl)");
        api.put("M_MoveR","(m_hdl,x, y)");
        api.put("M_ MoveR_D","(m_hdl,x, y)");
        api.put("M_MoveTo","(m_hdl,x, y)");
        api.put("M_ MoveTo_D","(m_hdl,x, y)");
        api.put("M_GetCurrMousePos","(m_hdl,x, y)");
        api.put("M_GetCurrMousePosX","(m_hdl)");
        api.put("M_GetCurrMousePosY","(m_hdl)");
        api.put("M_MoveR2","(m_hdl,x, y)");
        api.put("M_ MoveR2_D","(m_hdl,x, y)");
        api.put("M_MoveTo2","(m_hdl,x, y)");
        api.put("M_ MoveTo2_D","(m_hdl,x, y)");
        api.put("M_GetCurrMousePos2","(x, y)");
        api.put("M_ResolutionUsed","(m_hdl,x, y)");
        api.put("M_MoveTo3","(m_hdl,x, y)");
        api.put("M_MoveTo3_D","(m_hdl,x, y)");
        //=====================================================================================================
        Map<String,String> tableMap = new HashMap<>();
        File file = new File("C:\\Users\\gaoyihong\\Desktop\\新建文件夹\\API名随机化DLL及静态库(64位DLL)\\api对照列表.txt");
        String[] values = readFile(file).split("\n");
        for(int i=3;i<values.length;i++){
            String[] keys = values[i].trim().split(" ");
            for(int j=0;j<keys.length;j++){
                if(!"".equals(keys[j])){
                    String keyMap="";
                    if(j!=0){
                        tableMap.put(keys[0],keys[j]);
                    }

                }
            }
        }
        //======================================================================================

//        Iterator<Map.Entry<String, String>> it = tableMap.entrySet().iterator();
//        while (it.hasNext()) {
//            Map.Entry<String, String> m = it.next();
//            System.out.println("int "+ m.getValue()+" " +hashMaps.get(m.getKey())+";");
//        }
        //======================================================================================

        String className = "MSDK64";
        Iterator<Map.Entry<String, String>> it = tableMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> m = it.next();
            System.out.println("public static int "+ m.getKey()+" " +hashMaps.get(m.getKey())+"{return " + className +".WINAPI."+m.getValue()+api.get(m.getKey())+";}\n");
        }

        //======================================================================================




    }
    private static String readFile(File file)  {
        try {
            InputStream inputStream = new FileInputStream(file);
            return readInputStream(inputStream);
        } catch (Exception e) {
            System.err.println("文件找不到读写失败了");
        }
        return "";
    }
    private static String readInputStream(InputStream inputStream)  {
        try {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5 * 1024 * 1024);
            String str = "";
            int item = bufferedInputStream.read();
            if (item == -1) {
                return null;
            } else {
                str = str + "" + (char) item;
                int len = bufferedInputStream.available();
                if (len > 0) {
                    byte[] dats = new byte[len];
                    bufferedInputStream.read(dats);
                    str = str + new String(dats, "UTF-8");
                }
                inputStream.close();
                bufferedInputStream.close();
                return new String(str.getBytes("UTF-8"), "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
